<?php

namespace App\Kuafu\Mybank\Service;

use App\Kuafu\Base\Service\BaseService;
use App\Kuafu\Mybank\Model\MybankBillRecordModel;
use App\Kuafu\Mybank\Model\MybankEntryModel;
use App\Kuafu\Mybank\Model\MybankShopBindModel;
use App\Kuafu\Shop\Model\Shop;
use App\Kuafu\Shop\Resources\B\ShopSimpleResource;
use App\Kuafu\Shop\Service\ShopService;
use App\Remote\Mybank\Remote;
use App\Scope\ShopScope;

class MybankCallbackService extends BaseService
{
    public static function returnSuccessXml(array $resultJson)
    {
        return self::baseResresponseData($resultJson['request']['head'], [
            'RespInfo' => [
                'ResultStatus' => 'S',
                'ResultCode'   => '0000',
                'ResultMsg'    => '成功'
            ]
        ]);
    }


    public static function baseResresponseData(array $head, array $body)
    {
        $head = array_filter($head, function ($item) {
            return isset($item);
        });
        $body = array_filter($body, function ($item) {
            return isset($item);
        });
        ksort($head);
        ksort($body);

        $headXml = Remote::arr2xml($head, false);
        $body    = Remote::arr2xml($body, false);

        $xmlTemplate = <<<TEMPLATE
<?xml version="1.0" encoding="utf-8"?><document><response id="response"><head>{$headXml}</head><body>{$body}</body></response></document>
TEMPLATE;

        return Remote::xmlSignData($xmlTemplate);
    }


}
